<template>
<el-dialog :append-to-body="true" :title="files.title" :visible.sync="files.show" width="418px" :close-on-click-modal="false">
    <el-select popper-class="select-file-select" style="width:100%" clearable filterable v-model="files.filePath" :placeholder="files.placeholder">
        <el-option v-for="(item, i) in dataTables" :key="i" :label="item.fileName" :value="item.filePath"></el-option>
    </el-select>
    <span slot="footer" class="dialog-footer">
      <el-button @click="files.show=false">取 消</el-button>
      <el-button type="primary" v-preventReClick="2000" @click="handleConfirm">确 定</el-button>
    </span>
</el-dialog>
</template>

<script>
import {
    mapGetters
} from 'vuex'
export default {
    name: 'SelectFile',
    props: {
        files: {
            type: Object,
            required: true
        }
    },
    computed: {
        ...mapGetters({
            dataTables: 'common/getDataTables'
        })
    },
    methods: {
        handleConfirm () {
            if (this.files.filePath) {
                this.$emit('save', this.files.filePath)
            } else {
                this.$message.error(this.files.placeholder)
            }
        }
    }
}
</script>

<style lang="less">
.select-file-select {
    width: 378px;
}
</style>
